package com.dc.trans.steps.customperform;


import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.trans.Trans;
import org.pentaho.di.trans.TransMeta;
import org.pentaho.di.trans.step.BaseStep;
import org.pentaho.di.trans.step.StepDataInterface;
import org.pentaho.di.trans.step.StepInterface;
import org.pentaho.di.trans.step.StepMeta;
import org.pentaho.di.trans.step.StepMetaInterface;



public class Customperform extends BaseStep implements StepInterface {

	private static Class<?> PKG = Customperform.class;
	
	
	private CustomperformMeta meta;
	private CustomperformData data;
	
	private Customexecuter executer;
	private TransMeta transMeta;
	
	

	public Customperform(StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta, Trans trans) {
		super(stepMeta, stepDataInterface, copyNr, transMeta, trans);
		this.transMeta = transMeta;
	}
	
	public boolean init(StepMetaInterface smi, StepDataInterface sdi) {
		meta = (CustomperformMeta) smi;
		data = (CustomperformData) sdi;
		boolean flag=false;
		super.init(smi, sdi);
		
			
				try {
					executer=(Customexecuter)Class.forName(meta.getClassName()).newInstance();
					flag=true;
				} catch (InstantiationException e) {
					// TODO Auto-generated catch block
					log.logError("Customperform.init, An error occurred intialising this step: " ,e);
					stopAll();
					setErrors(1);
				} catch (IllegalAccessException e) {
					// TODO Auto-generated catch block
					log.logError("Customperform.init, An error occurred intialising this step: " ,e);
					stopAll();
					setErrors(1);
				} catch (ClassNotFoundException e) {
					// TODO Auto-generated catch block
					log.logError("Customperform.init, An error occurred intialising this step: " ,e);
					stopAll();
					setErrors(1);
				}

		return flag;
	}
	
	public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
		
		meta = (CustomperformMeta) smi;
		data = (CustomperformData) sdi;
		Custome cus = null;
		Object[] r = getRow();
		if (r ==null)
		{
			setOutputDone();
			return false;
		}
		try {
			 cus=executer.execute(getInputRowMeta(),meta, r);
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			logError("Because of an error, this step can't continue: ", e);
			setErrors(1);
			stopAll();
			setOutputDone(); // signal end to receiver(s)
			return false;
		}

			putRow(cus.getOutputRowMeta(),cus.getNewRowData());

		return true;
	}

	

	

	


	

	

	
	
}
